version 10.0
log using "C:\fsu2010\formateur\ajps\submission2\replication\analysis\compprob.log", replace
#delimit ;
set mem 30m;
clear matrix;
clear mata; 

set more off;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:  compprob.do                                         *;
*       Date:       December 6, 2010                                    *;
*       Author:     GG/MG                                               *;
*       Purpose:    Produce Figure 2 in Appendix D of SI for the AJPS   *
*                   paper.                                              *;
*       Input File:     europe.dta                                      *;
*       Output File:    compprob.log                                    *;
*       Data Output:    none                                            *;
*       Previous file:  europe.dta                                      *;
*       Machine:        Matt's desktop                                  *;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       Do a comparison of MXL and CL probabilities                     *;
*     ****************************************************************  *;

use "C:\fsu2010\formateur\ajps\submission2\replication\analysis\europe.dta", clear;

generate tempseats = party_seatshare;
by cabinetcode: egen tseats = max(tempseats);
replace tempseats = 0 if largestparty==1;
by cabinetcode: egen tseats2 = max(tempseats);

generate ss2 = party_seatshare;
replace ss2 = tseats if party_seatshare==tseats2;
replace ss2 = tseats2 if party_seatshare==tseats;

generate ss2e = ss2 * east;

generate largep2 = 0;
replace largep2 = 1 if party_seatshare==tseats2;

generate largep2e = largep2 * east;

generate ss3 = party_seatshare;
generate largep3 = largestparty;
generate ss3e = party_seatshare_east;
generate largep3e = largestparty_east;

clogit choice largestparty_east party_seatshare_east medianparty1_east presidentparty_east previousPM_east previousPM_conflict_east previousPM_gain1_east previous_cabinet_gain1_east 
largestparty party_seatshare medianparty1 presidentparty previousPM president_investiture president_direct previousPM_conflict previousPM_gain1 previous_cabinet_gain1, group(cabinetcode);

predict clprob, p;

replace largestparty = largep2;
replace party_seatshare = ss2;
replace largestparty_east = largep2e;
replace party_seatshare_east = ss2e;

predict clprob2, p;

replace largestparty = largep3;
replace party_seatshare = ss3;
replace largestparty_east = largep3e;
replace party_seatshare_east = ss3e;


mixlogit choice largestparty_east party_seatshare_east medianparty1_east presidentparty_east previousPM_east previousPM_conflict_east previousPM_gain1_east previous_cabinet_gain1_east,  
    rand (largestparty party_seatshare medianparty1 presidentparty previousPM president_investiture president_direct previousPM_conflict previousPM_gain1 previous_cabinet_gain1) 
    ln(0) nrep(125) group(cabinetcode);

mixlpred mixprob;

replace largestparty = largep2;
replace party_seatshare = ss2;
replace largestparty_east = largep2e;
replace party_seatshare_east = ss2e;

mixlpred mixprob2;

replace largestparty = largep3;
replace party_seatshare = ss3;
replace largestparty_east = largep3e;
replace party_seatshare_east = ss3e;

generate mixdiff = mixprob2 - mixprob;
generate cldiff = clprob2 - clprob;

generate cldiff2 = cldiff^2;
generate cldiff3 = cldiff^3;
generate cldiff4 = cldiff^4;
generate cldiff5 = cldiff^5;

regress mixdiff cldiff cldiff2 cldiff3 cldiff4 cldiff5;
predict pxb, xb;

gen h = -1;
replace h = 1 if _n==1;
gen v = -1;
replace v = 1 if _n==1;


/* mark out points from hypothetical case */

generate mixdiffD = .;
replace mixdiffD = mixdiff if cabinetcode==1222 & partyID==7;
replace mixdiffD = mixdiff if cabinetcode==1222 & partyID==13;

generate mixdiffD2 = .;
replace mixdiffD2 = mixdiff if cabinetcode==1222 & partyID==22;

generate mixdiffD3 = .;
replace mixdiffD3 = mixdiff if cabinetcode==1222 & partyID==10;

generate partyname = "";
replace partyname = "PvdA" if cabinetcode==1222 & partyID==7;
replace partyname = "CDA" if cabinetcode==1222 & partyID==13;
replace partyname = "VVD" if cabinetcode==1222 & partyID==22;
replace partyname = "D66" if cabinetcode==1222 & partyID==10;

sort cldiff;



graph twoway (scatter mixdiff cldiff, msymbol(oh) mcolor(gs8) ylabel(-1 -0.5 0 0.5 1) xlabel(-1 -0.5 0 0.5 1) 
        ytitle("Mixed Logit Probability") xtitle("Conditional Logit Probability") plotregion(margin(zero)) legend(off)) 
            (line h v, lcolor(black) lwidth(thin)) (scatter pxb cldiff, connect(l) msymbol(i) lcolor(black))
            (scatter mixdiffD cldiff, msymbol(o) mcolor(black) mlabel(partyname) mlabcolor(black) mlabsize(small) mlabposition(3))
            (scatter mixdiffD2 cldiff, msymbol(o) mcolor(black) mlabel(partyname) mlabcolor(black) mlabsize(small) mlabposition(11))
            (scatter mixdiffD3 cldiff, msymbol(o) mcolor(black) mlabel(partyname) mlabcolor(black) mlabsize(small) mlabposition(4));

graph twoway (scatter mixdiff cldiff, msymbol(oh) mcolor(gs8) ylabel(-1 -0.5 0 0.5 1) xlabel(-1 -0.5 0 0.5 1) plotregion(margin(zero)) legend(off)
            yline(-0.5 0 0.5 10 0.2 0.4 0.6 0.8 1, lcolor(white)) xtitle("" , size(2.5)) scheme(s2mono) graphregion(fcolor(white)))
            (line h v, lcolor(black) lwidth(thin)) (scatter pxb cldiff, connect(l) msymbol(i) lcolor(black))
            (scatter mixdiffD cldiff, msymbol(o) mcolor(black) mlabel(partyname) mlabcolor(black) mlabsize(small) mlabposition(3))
            (scatter mixdiffD2 cldiff, msymbol(o) mcolor(black) mlabel(partyname) mlabcolor(black) mlabsize(small) mlabposition(11))
            (scatter mixdiffD3 cldiff, msymbol(o) mcolor(black) mlabel(partyname) mlabcolor(black) mlabsize(small) mlabposition(4));

